<script setup lang="ts">
import type { ActionSheetAction } from 'vant'
import { ref } from 'vue'

interface IPickerDate {
  selectedValues: string[]
  selectedOptions: {
    text: string
    value: string
  }[]
  selectedIndexes: number[]
}
const columns = [
  {
    text: '浙江',
    value: 'Zhejiang',
    children: [
      {
        text: '杭州',
        value: 'Hangzhou',
        children: [
          { text: '西湖区', value: 'Xihu' },
          { text: '余杭区', value: 'Yuhang' },
        ],
      },
      {
        text: '温州',
        value: 'Wenzhou',
        children: [
          { text: '鹿城区', value: 'Lucheng' },
          { text: '瓯海区', value: 'Ouhai' },
        ],
      },
    ],
  },
  {
    text: '福建',
    value: 'Fujian',
    children: [
      {
        text: '福州',
        value: 'Fuzhou',
        children: [
          { text: '鼓楼区', value: 'Gulou' },
          { text: '台江区', value: 'Taijiang' },
        ],
      },
      {
        text: '厦门',
        value: 'Xiamen',
        children: [
          { text: '思明区', value: 'Siming' },
          { text: '海沧区', value: 'Haicang' },
        ],
      },
    ],
  },
]
const isShowArea = ref(false)
const isShowCamera = ref(false)

const onClicikCAmera = (action: ActionSheetAction, index: number) => {
  if (index === 0) {
    // 拍照
  } else {
    // 相册
  }
  console.log('index  ----->  ', index)
}

//日期选择器
const isShowBirthday = ref(false)

const onSelectBirth = ({ selectedValues }: IPickerDate) => {
  console.log('date  ----->  ', selectedValues)
}
</script>

<template>
  <div class="profile-edit-page">
    <!-- 头像部分 -->
    <div class="avatar">
      <van-image
        round
        width="100"
        height="100"
        class="avatar-img"
        src="https://foruda.gitee.com/avatar/1716533299289369832/5539886_yjh8866_1716533299.png"
      >
      </van-image>
      <div class="avatar-btn" @click="isShowCamera = true">
        <span>修改头像</span>
      </div>
    </div>

    <!-- 中间表单部分 -->
    <van-cell-group>
      <van-field label="账号" readonly></van-field>
      <van-field label="昵称" placeholder="请输入昵称"></van-field>
      <van-cell title="性别" class="gender">
        <van-radio-group :icon-size="16">
          <van-radio name="男">男</van-radio>
          <van-radio name="女">女</van-radio>
          <van-radio name="未知">未知</van-radio>
        </van-radio-group>
      </van-cell>
      <van-field
        label="生日"
        readonly
        placeholder="请选择日期"
        @click="isShowBirthday = true"
      ></van-field>
      <van-field
        label="所在地"
        readonly
        placeholder="请选择所在地"
        @click="isShowArea = true"
      ></van-field>
      <van-field label="职业" readonly placeholder="请选择职业"></van-field>
    </van-cell-group>

    <div class="submit">
      <van-button round block type="primary"> 保存资料 </van-button>
    </div>

    <van-action-sheet
      v-model:show="isShowCamera"
      :actions="[{ name: '相册' }, { name: '拍照' }]"
      @select="onClicikCAmera"
      cancel-text="取消"
      :style="{ paddingBottom: '20px' }"
    ></van-action-sheet>
    <VanPopup v-model:show="isShowBirthday" position="bottom">
      <van-date-picker
        @confirm="onSelectBirth"
        title="选择日期"
        @cancel="isShowBirthday = false"
        :min-date="new Date(1900, 0, 1)"
        :max-date="new Date()"
      ></van-date-picker>
    </VanPopup>
    <VanPopup title="选择地区" v-model:show="isShowArea" position="bottom">
      <VanPicker :columns="columns" @cancel="isShowArea = false"></VanPicker>
    </VanPopup>
  </div>
</template>

<style lang="css" scoped>
.avatar {
  padding: 30px;
  text-align: center;
  background-color: var(--mk-white);
}

.avatar-img {
  box-shadow: 0 0 5px #ccc;
}

.avatar-btn {
  color: var(--mk-linear_end);
  margin-top: 10px;
}

.gender ::v-deep(.van-cell__title) {
  width: 100px;
  flex: none;
}

.van-radio-group {
  display: flex;
  justify-content: space-between;
  height: 36px;
  width: 180px;
}

.submit {
  padding: 16px;
}
</style>
